package com.eas.biz.utils;

import java.util.List;
import java.util.Random;

public class StringUtils {

    private final static String EMPTY_SYMBOL = "-";

    /**
     * @param psStr
     * @return
     */
    public static boolean isEmpty(String psStr) {
        if (psStr == null || "".equals(psStr)) {
            return true;
        }

        return false;
    }

    /**
     * @param psStr
     * @return
     */
    public static boolean isNotEmpty(String psStr) {
        if (psStr != null && !"".equals(psStr)) {
            return true;
        }

        return false;
    }

    /**
     * @param piLength
     * @return
     */
    public static String getRandom(Integer piLength) {
        String random = "";
        Random rand = new Random();
        for (int i = 0; i < piLength; i++) {
            random = random + rand.nextInt(10);
        }
        return random;
    }

    /**
     * 格式化str
     * 
     * @param psStr
     * @return
     */
    public static String escapeNull(String psStr) {
        return psStr == null || psStr.equals("") ? EMPTY_SYMBOL : psStr;
    }

    /**
     * 格式化str
     * 
     * @param psStr
     * @return
     */
    public static String escapeNull(Integer piInt) {
        return piInt == null ? EMPTY_SYMBOL : piInt.toString();
    }

    public static String array2String(String[] pasStr, String psSplit) {
        if (pasStr == null || pasStr.length == 0) {
            return "";
        }

        StringBuffer sb = new StringBuffer();
        for (String str : pasStr) {
            sb.append(str);
            sb.append(psSplit);
        }
        return sb.substring(0, sb.length() - 1);
    }

    /**
     * 转换特殊字符
     */
    public static String conversion(String str) {
        str = str.replaceAll("&", "&amp;");
        str = str.replaceAll("<", "&lt;");
        str = str.replaceAll(">", "&gt;");
        str = str.replaceAll("\'", "&rsquo;");
        str = str.replaceAll("\"", "&quot;");
        str = str.replaceAll("\\\\", "&#92;");

        return str;
    }

    public static boolean isListEmpty(List<Object> list) {
        return list == null || list.size() <= 0;
    }
}
